package com.x.Part2_Exception类.运行时异常;

import java.util.Date;
import java.util.Scanner;

/**
 * ClassName: Test
 * Package: IntelliJ IDEA
 * Description:运行时异常举例
 * Written by HanXu
 * Create 2024.03.17 14:33
 */
public class Test1 {


    @org.junit.Test
    //NullPointerException
    public void test1(){
        int[] arr =new int[10];
        arr = null;
        System.out.println(arr[0]);
    }

    @org.junit.Test
    //ClassCastException
    public void test2() {
        Object obj = new String();
        //String str = (String) obj;
        Date date = (Date) obj;
    }

    @org.junit.Test
    //NumberFormatException
    public void test3() {
        String str ="123";
        str="1bc";
        int i = Integer.parseInt(str);
        System.out.println(i);
    }

    @org.junit.Test
    //InputMismatchException
    public void test4() {
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        System.out.println(i);
    }

    @org.junit.Test
    //ArithmeticException
    public void test5() {
        System.out.println(10/0);
    }

    }



